Field of the Invention
The present invention generally relates to three-dimensional (3D) graphics processing, and, more particularly, to setting downstream render state in an upstream shader.
Description of the Related Art
Computer generated images that include 3D graphics objects are typically rendered using a graphics processing unit (GPU) with one or more multistage graphics pipelines. Such graphics pipelines include various programmable and fixed function stages. Programmable stages include various processing units that execute shader programs to render graphics objects and to generate various visual effects associated with graphics objects. These shaders programs include: (i) vertex shaders that transform the 3D position of each vertex associated with a graphics object to a 2D position on the screen surface of a display device; (ii) tessellation shaders that divide graphics objects into smaller graphics objects or graphics primitives, such as lines and triangles; (iii) geometry shaders that receive geometric primitives and generate fragments, each of which includes one or more picture elements (pixels); and (iv) pixel shaders that receive the fragments and compute color and other attributes of each individual pixel. Various fixed function stages exist in the pipeline among the programmable shaders, where those fixed function stages perform specific defined functions within the pipeline. Such fixed function stages include viewport culling units, clipping units, setup calculation units, rasterization units, and units configured to perform preROP (pre-raster operations), color operations, or depth buffer operations.
Typically, in a graphics-based implementation, a central processing unit (CPU) transmits graphics objects to the GPU for rendering and display. The CPU may also transmit certain state conditions for the various programmable and fixed stages in the graphics pipeline. However, these state conditions are sent before or after sending a graphics object. As such, the state parameters are fixed when rendering a particular graphics object.
Because the state parameters of the graphics pipeline stages are fixed when rendering a particular graphics object, certain visual effects are cumbersome to generate. For example, hair or fur can be rendered with anti-aliased polylines, where a polyline includes multiple line segments connected in series. A realistic appearance can be achieved by varying the thickness of the polyline such that line segments that are nearer to the screen surface of a display device are thicker than line segments farther away from the screen surface. However, the CPU generally cannot change the thickness of line segments in a given polyline. As a result, the anti-aliased line segments of a given polyline are of uniform thickness. This can give the appearance of a strand of hair that is two thin in the front and too thick in the back.
One possible solution to the above problem is that the CPU can divide a graphics object into smaller graphics objects or into graphics primitives, a process called tessellation. The CPU can then update the state parameters between transmission of the smaller graphics objects or graphics primitives, providing more flexibility in generating various effects. As an example, each line segment of a polyline could be separately transmitted from the CPU to the GPU, where the CPU specifies the thickness of each separately transmitted line segment. One drawback with this approach is that the CPU is less efficient in performing tessellation operations than the GPU. By moving some or all of an entire tessellation task from the GPU to the CPU, overall system performance is reduced. Alternatively, the GPU can continue to perform tessellation, but certain effects are not going to be achievable because of the limitations described above.
As the foregoing illustrates, what is needed in the art is an improved technique for processing graphics objects in a graphics pipeline.